# coding: utf-8

# NOTE by zhouhl 2018-066-28
# 将七月拉新的用户信息写入 user_marketing_info_july 表
# 查询真实的，且未绑定过微信的工程商与潜在工程商

import os
import set_env_path

from sqlalchemy import create_engine
from sqlalchemy.sql import text

engine = create_engine(
    os.getenv('DATABASE_URL')
    or 'mysql+pymysql://root:@127.0.0.1/wph_www_prod?charset=utf8'
)
conn = engine.connect()


def insert_into_user_marketing_info_july():
    find_user_sql = text("""
        select id,area_id,mobile from user where type in(99,100) and is_virt=0 and wx_openid='' and bind_wx_openid=0 order by id asc;
    """)

    insert_info_sql = text("""
        insert into user_marketing_info_july (
            user_id, mobile, area_id, status
        ) values (
            :user_id, :mobile, :area_id, 10
        );
    """)

    records = conn.execute(find_user_sql).fetchall()
    for i in records:
        conn.execute(
            insert_info_sql,
            user_id=i.id,
            mobile=i.mobile,
            area_id=str(i.area_id)[:2] + '0000',
        )


if __name__ == '__main__':
    insert_into_user_marketing_info_july()
